package com.cci.kangdao.dao;

import com.cci.kangdao.dao.model.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;
import java.util.Map;


@MapperScan
public interface CRMPlatformServiceDao {
	
	/**
	 * 根据服务站编号和服务站与故障地点距离获取服务站维修范围表	
	 */
	@Select("SELECT top 1 * FROM ServiceStation_T ss\n" +
			"INNER JOIN SSRepair_T respair\n" + 
			"ON ss.ID = respair.ServiceStationID\n" + 
			"INNER JOIN Company_T company\n" + 
			"ON company.ID = respair.CompanyID\n" + 
			"WHERE respair.BusinessNo = #{BusinessNo} AND company.CompanyNo = #{CompanyNo} AND respair.Flag = 0 and ss.Flag != -1")
	public ServiceStationT getServiceStationByBusinessNoAndCompanyNo(Map<String, Object> map);
	
	/**
	 * 根据工单编号获取工单外出轨迹点集合
	 * @param orderNo
	 * @return
	 */
	public List<Map<String,Object>> getWorkOrderTrack(String orderNo);
	
	/**
	 * 插入服务站数据数据
	 * @Title: insertServiceStationInfo  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int insertServiceStationInfo(Map<String,Object> map);

	 /**
	  * @description: 二网和一网关系中间表
	  * @param:
	  * @return:
	  * @exception:
	  * @author: shiliqiang
	  * @company: CTY Technology Co.,Ltd
	  * @since: 2022/5/30 13:25
	  * @version: V1.0
	  */
	 int insertServiceStationRelationInfo(Map<String,Object> map);

	int updateServiceStationRelationInfo(Map<String,Object> map);

	  /**
	   * @description:查询二网关系表
	   * @param:
	   * @return:
	   * @exception:
	   * @author: shiliqiang
	   * @company: CTY Technology Co.,Ltd
	   * @since: 2022/6/6 14:26
	   * @version: V1.0
	   */
	 List<Map<String,Object>> queryServiceStationRelationInfo(Map<String,Object> map);


	/**
	 * @Author Joe
	 * @Description 测试表数据
	 * @Date 4:48 PM 2019/4/11
	 * @Param [map]
	 * @return int
	 **/
	@Insert("INSERT INTO ServiceStation_CRM_T(StationCRMData,Systime) VALUES (#{StationCRMData},#{Systime})")
	public int insertServiceStationCRMInfo(Map<String,Object> map);
	
	/**
	 * 根据CompanyNo获取CompanyID
	 * @Title: getCompanyByCompanyNo  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return CompanyT   
	 * @throws
	 */
	@Select("SELECT * FROM Company_T WHERE Company_T.CompanyNo = #{company}'")
	public CompanyT getCompanyByCompanyNo(Map<String,Object> map);
	
	
	/**
     * 记录服务站的保内保外信息
     * @param ssId
     * @param list
     */
    void SSHasServiceType(@Param("ssId") Long ssId, @Param("list") List<String> list);
    
    /**
     * 记录服务站的车辆应用信息
     * @param ssId
     * @param list
     */
    void SSHasVehicleType(@Param("ssId") Long ssId, @Param("list") List<String> list);
    
    /**
     * 记录服务站车辆厂家信息
     * @param ssId
     * @param list
     */
    @Deprecated
    void SSHasCompany(@Param("ssId") Long ssId, @Param("list") List<String> list);
    
    /**
     * 获取服务站保内保外信息
     * @param ssId
     * @return
     */
    List<Integer> getSSHasServiceType(Long ssId); 
    
    /**
     * 获取服务站车辆应用
     * @param ssId
     * @return
     */
    List<Integer> getSSHasVehicleType(Long ssId);

    
    /**
     * 记录服务站的发动机机型信息
     * @Title: SSHasEngineType  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param ssId
     * @param @param list
     * @return void   
     * @throws
     */
    void SSHasEngineType(@Param("ssId") Long ssId,@Param("companyId") Long companyId,@Param("list") List<Long> list);

	/**
	 * 根据typeName查询出对应的EngineType数据
	 *
	 * @param @param  map
	 * @param @return
	 * @return EngineTypeT
	 * @throws
	 * @Title: getEngineTypeByTypename
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 */
//    @Select("<script>select ID from EngineType_T where TypeName in <foreach collection='typeName' item='item' open='(' separator=',' close=')'>       #{item}  </foreach>  </script>")
//    public List<Long> getEngineTypeByTypename(@Param("typeName") List<String> typeNames);

	/**
	 * 记录服务站维修表
	 *
	 * @param @param  map
	 * @param @return
	 * @return int
	 * @throws
	 * @Title: insertSSRepairInfo
	 * @Description: TODO(这里用一句话描述这个方法的作用)
     */
    public int insertSSRepairInfo(Map<String, Object> map);
    
    /**
     * 根据ID更新服务站数据
     * @Title: updateStaionNoByPrimaryKey  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param map
     * @param @return
     * @return int   
     * @throws
     */
    public int updateStationInfoByPrimaryKey(Map<String, Object> map);
    
    /**
     * 根据ServiceStationID更新SSRepair数据
     * @Title: updateSSRepairInfoByServiceStationID  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param map
     * @param @return
     * @return int   
     * @throws
     */
    public int updateSSRepairInfoByServiceStationID(Map<String, Object> map);
    
    /**
     * 根据服务站ID和企业ID获取SSRepairT
     * @Title: getSSRepairInfoByServiceStionIDAndCompanyNo  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param serviceStaionID
     * @param @param CompanyID
     * @param @return
     * @return SSRepairT   
     * @throws
     */
    @Select("SELECT * FROM SSRepair_T re\n" + 
    		"INNER JOIN Company_T co\n" + 
    		"ON co.ID = re.CompanyID\n" + 
    		"WHERE co.CompanyNo = #{CompanyNo} AND re.ServiceStationID = #{serviceStaionID}")
    public SSRepairT getSSRepairInfoByServiceStionIDAndCompanyNo(@Param("serviceStaionID") Long serviceStaionID, @Param("CompanyNo") String CompanyNo);
    
    /**
     * 查询所有的异常数据（FLAG=0）
     * @Title: getAPIExceptions  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @return
     * @return List<Map<String,Object>>   
     * @throws
     */
    public List<Map<String,Object>> getAPIExceptions(@Param("companyNo") String companyNo);
    
    /**
     * 
     * @Title: updateAPIExceptions  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param exceptions
     * @param @return
     * @return int   
     * @throws
     */
    public int updateAPIExceptions(@Param("exceptions") List<Map<String,Object>> list);
    
    /**
     * 根据电话号码获取到唯一的User信息
     * @Title: getUserByPhone  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param phone
     * @param @return
     * @return UserT   
     * @throws
     */
    @Select("SELECT * FROM User_T WHERE Phone = #{phone} AND Flag = 0")
    public UserT getUserByPhone(@Param("phone") String phone);
    
    /**
     * 根据TypeName获取ID
     * @Title: getEngineTypeIDByTypeName  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param typeName
     * @param @return
     * @return long   
     * @throws
     */
    @Select("SELECT ID FROM EngineType_T WHERE TypeName = #{typeName} AND Flag = 0")
    public List<Long> getEngineTypeIDByTypeName(@Param("typeName") String typeName);
    
    /**
     * 查询SSAuth
     * @Title: getSSAuthIdsByDValues  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param list
     * @param @return
     * @return List<Long>   
     * @throws
     */
    @Select({"<script>" +
            "select ID from Dictionaries_T where DValue in" +
            "<foreach item = 'item' index = 'index' collection = 'list' open = '(' separator = ',' close = ')'>#{item}</foreach>" +
            "</script>"})
    public List<Long> getSSAuthIdsByDValues(@Param("DValues") List<String> list);
    
    /**
     * 插入技师资质表
     * @Title: insertEngineerQualify_T  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param map
     * @param @return
     * @return int   
     * @throws
     */
    public int insertEngineerQualify_T(Map<String,Object> map);
    
    /**
     * 根据电话号码查询技师资质
     * @Title: getEngineerQualifyByPhone  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param phone
     * @param @return
     * @return Long   
     * @throws
     */
    @Select("SELECT ID FROM EngineerQualify_T WHERE UserPhone = #{phone} AND Flag = 0")
    public List<Long> getEngineerQualifyByPhone(@Param("phone") String phone);
    
 
    /**
     * 现将技师资质作废
     * @Title: updateEngineerQualifyByPhone  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param phone
     * @param @return
     * @return int   
     * @throws
     */
    @Update("UPDATE EngineerQualify_T SET Flag = #{flag} WHERE UserPhone = #{phone}")
    public int updateEngineerQualifyStatusByPhone(@Param("phone") String phone,@Param("flag") int flag);

	/**
	 * 更新市场类型
	 */
	@Update("update WorkOrder_T set MarketType = #{marketType} where OrderNo = #{orderNo}")
	public int updateMarketTypes(@Param("marketType") String marketType,@Param("orderNo") String orderNo);

	/**
	 * 更新应用程序
	 */
	@Update("update WorkOrder_T set Application = #{application} where OrderNo = #{orderNo}")
	public int updateApplication(@Param("application") String application,@Param("orderNo") String orderNo);

    
    /**
     * 更新EngineerQualify_T table数据
     * @Title: insertOrUpdateEngineerQualifyByPhone  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param phone
     * @param @param EngineTypeName
     * @param @return
     * @return int   
     * @throws
     */
//    @Select("if not exists (select * from EngineerQualify_T where UserPhone = #{UserPhone} and EngineTypeName = #{EngineTypeName})\n" +
//    		"	insert into \n" +
//    		"	EngineerQualify_T (UserName, UserPhone,EngineTypeId,Flag,Creator, CreateTime, \n" +
//    		"	Updator, UpdateTime, Deleter, DeleteTime,  EngineTypeName, SSAuthValue)\n" +
//    		"	values\n" +
//    		"	('#{UserName}','#{UserPhone}', '#{EngineTypeId}','#{Flag}','#{Creator}','#{CreateTime}',#{Updator},#{UpdateTime},#{Deleter},#{DeleteTime},#{EngineTypeName},#{SSAuthValue})\n" +
//    		"else \n" +
//    		"	update EngineerQualify_T set Flag = 0 where UserPhone = #{UserPhone} and EngineTypeName = #{EngineTypeName}")
//    public int insertOrUpdateEngineerQualifyByPhone(Map<String,Object> map);
    
    
    /**
     * 创建工单
     * @Title: CreateWorkOrder  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param list
     * @param @return
     * @return int   
     * @throws
     */
    public int CreateWorkOrder(Map<String,Object> map);
    
    /**
     * 根据工单号查询工单ID
     * @Title: getOldOrderIDByOrderNo  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param orderNo
     * @param @return
     * @return long   
     * @throws
     */
    @Select("SELECT ID FROM WorkOrder_T WHERE OrderNo = #{orderNo}")
    public long getOldOrderIDByOrderNo(@Param("APPOrderNo") String orderNo);
    
   
    /**
     * 旧工单关联新工单表id
     * @Title: updateRelOrderId  
     * @Description: TODO(这里用一句话描述这个方法的作用)  
     * @param @param map
     * @param @return
     * @return int   
     * @throws
     */
	public int updateRelOrderId(Map<String, Object> map);
	
	/**
	 * 根据orderNo查询工单信息
	 * @Title: getOldOrderInfoByOrderNo  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param orderNo
	 * @param @return
	 * @return long   
	 * @throws
	 */
	@Select("SELECT * FROM WorkOrder_T WHERE OrderNo = #{APPOrderNo}")
	public Map<String,Object> getOldOrderInfoByOrderNo(@Param("APPOrderNo") String orderNo);
	
	/**
	 * 更新工单表数据
	 * @Title: updateWorkOrderInfo  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int updateWorkOrderInfo(Map<String,Object> map);
	
	/**
	 * 保存异常信息到APP异常信息表
	 * @Title: saveExceptionToTable  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int saveExceptionToTable(Map<String,Object> map);
	
	/**
	 * 保存异常信息到APP异常信息表
	 * @Title: saveExceptionToExpTable  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param exception
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int saveExceptionToExpTable(APIExceptionT exception);
	
	/**
	 * 保存职位信息
	 * @Title: savePositionInfoToTable  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int savePositionInfoToTable(Map<String,Object> map);

	/**
	 * 根据岗位编号，查询岗位信息
	 * @Title: getPositionInfoToTableByCrmPostNoAndCreator
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param map
	 * @param @return
	 * @return int
	 * @throws
	 */

	@Select("SELECT * FROM Position_T WHERE CrmPostNo = #{CrmPostNo} And Level = #{Level} AND Creator = #{Creator} AND Flag = 0")
	public Map<String,Object> getPositionInfoToTableByCrmPostNoAndCreator(Map<String,Object> map);

	/**
	 * @Author Joe
	 * @Description 查询 PositionUser_T信息
	 * @Date 10:32 AM 2019/4/15
	 * @Param [map]
	 * @return java.util.Map<java.lang.String,java.lang.Object>
	 **/
    @Select("SELECT * FROM PositionUser_T WHERE UserPhone = #{UserPhone} AND PositionID = #{PositionID} AND Flag = 0")
	public Map<String,Object> getPositionUserInfoByCrmPositionIDAndPhoneANDCreator(Map<String,Object> map);
    @Select("SELECT distinct * FROM PositionUser_T WHERE CrmId =#{CrmId} AND Flag = 0")
	public Map<String,Object> getPositionUserInfoByCrmPositionIDAndPhoneANDCreatorDbu(Map<String,Object> map);

	/**
	 * dcec,ccec渠道时校验调用
	 * @param map
	 * @return
	 */
	@Select("SELECT distinct * FROM PositionUser_T WHERE UserPhone = #{UserPhone} AND PositionID = #{PositionID} AND Flag = 0")
	public Map<String,Object> getPositionUserInfoByCrmPositionIDAndPhoneANDCreatorOrder(Map<String,Object> map);

	/**
	 * @Author Joe
	 * @Description 获取PositionUserServiceStation_T信息
	 * @Date 11:02 AM 2019/4/15
	 * @Param [map]
	 * @return java.util.Map<java.lang.String,java.lang.Object>
	 **/
	@Select("SELECT * FROM PositionUserServiceStation_T WHERE ServiceStationNo = #{ServiceStationNo} AND CompanyID = #{CompanyID} AND PositionUserID = #{PositionUserID} AND Flag = 0")
	public Map<String,Object> getPositionUserServiceStationInfoByServiceStationNoAndCompanyIDANDPositionID(Map<String,Object> map);


    List<Map<String, Object>> getPositionUserServiceStationInfoByServiceStationNoAndCompanyIDANDPositionIDList(@Param("list") List<Map<String, Object>> list, @Param("companyId") Long companyId);

	/**
	 * @author zyx
	 * @desc 根据服务站和渠道获取PositionUserServiceStation_T信息
	 * @param userServiceMap
	 * @return
	 */
	@Select("SELECT * FROM PositionUserServiceStation_T WHERE ServiceStationNo = #{ServiceStationNo} AND CompanyID = #{CompanyID} AND Flag = 0")
	public List<Map<String, Object>> getPositionUserServiceStationInfoByServiceStationNoAndCompanyID(Map<String, Object> userServiceMap);

	/**
	 * 更新职位信息
	 * @Title: updatePositionInfoToTable  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int updatePositionInfoToTable(Map<String,Object> map);
	/**
	 * 删除职位信息
	 * @Title: savePositionInfoToTable  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int deletePositionInfoToTable(Map<String,Object> map);
	
	/**
	 * 保存职位人员信息
	 * @Title: savePositionContactToTable  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	 int savePositionContactToTable(Map<String,Object> map);

	int savePositionUserList(List<Map<String,Object>> list);
	/**
	 * 更新职位人员信息
	 * @Title: updatePositionContactToTable  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int updatePositionContactToTable(Map<String,Object> map);

	/**
	 * 更新职位人员信息Dbu
	 * @Title: updatePositionContactToTable
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param map
	 * @param @return
	 * @return int
	 * @throws
	 */
	public int updatePositionContactToTableDbu(Map<String,Object> map);

	public int updatePositionContactToTableDbuList(List<Map<String,Object>> list);
	/**
	 * 更新职位人员信息dcec
	 * @param map
	 * @return
	 */
	public int updatePositionContactToTableOrder(Map<String,Object> map);
	/**
	 * 删除职位人员信息Dbu
	 * @Title: deletePositionContactToTable
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param map
	 * @param @return
	 * @return int
	 * @throws
	 */
	public int deletePositionContactToTableDbu(Map<String,Object> map);

	/**
	 * 删除职位人员信息
	 * @Title: deletePositionContactToTable  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int deletePositionContactToTable(Map<String,Object> map);

	/**
	 * 删除职位人员信息dcec,xcec,ccec
	 * @param map
	 * @return
	 */
	public int deletePositionContactToTableOrder(Map<String,Object> map);

	/**
	 * 保存职位人员服务站关系信息
	 * @Title: savePositionUserServiceStationToTable  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int savePositionUserServiceStationToTable(Map<String,Object> map);

	 int savePositionUserServiceStationList(List<Map<String,Object>> map);
	/**
	 * 更新职位人员服务站关系信息
	 * @Title: updatePositionUserServiceStationToTable  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int updatePositionUserServiceStationToTable(Map<String,Object> map);
	/**
	 * 删除职位人员服务站关系信息
	 * @Title: deletePositionUserServiceStationToTable  
	 * @Description: TODO(这里用一句话描述这个方法的作用)  
	 * @param @param map
	 * @param @return
	 * @return int   
	 * @throws
	 */
	public int deletePositionUserServiceStationToTable(Map<String,Object> map);

	/**
	 * 删除管辖信息
	 * @param companyId 企业渠道ID
	 * @param positionUserId 用户职位ID
	 * @param deleteTime 删除时间
	 * @return 影响行数
	 */
	int deletePositionUserServiceStation(@Param("companyId") Long companyId,@Param("positionUserId") Long positionUserId,@Param("deleteTime") String deleteTime);


	int deletePositionUserServiceStationByChannelAndStationNo(Map<String,Object> map);

    List<Long> listByStationNoAndLevel(@Param("Level") String Level, @Param("ServiceStationNo") String ServiceStationNo);

	int deletePositionUserServiceStationByChannelAndStationId(Map<String,Object> map);

	/**
	 * @Author Joe
	 * @Description 根据工单编号更新crmNo
	 * @Date 6:48 PM 2019/4/2
	 * @Param [OrderNo]
	 * @return int
	 **/
	public int updateWOrkOrderByOrderNo(Map<String,Object> map);

	/**
	 * @Author Joe
	 * @Description 根据app工单号获取crm工单号
	 * @Date 2:22 PM 2019/4/4
	 * @Param [orderNo]
	 * @return java.lang.String
	 **/
	@Select("SELECT OrderNoCrm FROM WorkOrder_T WHERE OrderNo = #{APPOrderNo}")
	public String getCRMOrderNoByAPPOrderNo(@Param("APPOrderNo") String orderNo);

	/**
	 * @Author Joe
	 * @Description 根据工单号查询工单信息
	 * @Date 3:02 PM 2019/5/7
	 * @Param [orderNo]
	 * @return java.util.Map<java.lang.String,java.lang.Object>
	 **/
	@Select("SELECT COUNT(*) FROM WorkOrder_T WHERE OrderNo = #{orderNo}")
	public int getWorkOrderInfoByOrderNo(@Param("orderNo") String orderNo);

	/**
	 * @Author Joe
	 * @Description crm同步esn、userPhone信息到APP
	 * @Date 3:41 PM 2019/5/7
	 * @Param [map]
	 * @return int
	 **/
	public int updateWorkOrderInfoByOrderNoFromCRM(Map<String,Object> map);

	/**
	 * @Author Joe
	 * @Description 查询出所有没有OrderNoCrm的工单数据
	 * @Date 3:41 PM 2019/5/7
	 * @Param [map]
	 * @return int
	 **/
	@Select("SELECT * FROM WorkOrder_T WHERE OrderNoCrm IS NULL OR OrderNoCrm = ''")
	public List<Map<String,Object>> selectAllWorkOrderInfoNullOrderNoCrm();

	/**
	 * @Author Joe
	 * @Description 查询出所有没有OrderNoCrm的工单数据(根据工单号)
	 * @Date 3:41 PM 2019/5/7
	 * @Param [map]
	 * @return int
	 **/
	@Select("SELECT * FROM WorkOrder_T \n" +
			"WHERE OrderNo = #{orderNo} AND \n" +
			"ID IN (SELECT ID FROM WorkOrder_T WHERE OrderNoCrm IS NULL OR OrderNoCrm = '')")
	public Map<String,Object> selectAllWorkOrderInfoNullOrderNoCrmByOrderNo(@Param("orderNo") String orderNo);

	/**
	 * @Author Joe
	 * @Description 根据工单号查处工单状态负责人表数据
	 * @Date 5:55 PM 2019/7/4
	 * @Param [workOrder]
	 * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
	 **/
	@Select("select * from WorkOrderFlow_T where id \n" +
			"in (select max(id) from WorkOrderFlow_T WHERE OrderId = #{OrderId} \n" +
			"group by processStatus);")
	List<Map<String,Object>> getAllWorkOrderStatusByOrderId(@Param("OrderId") Long OrderId);

	/**
	 * @Author Joe
	 * @Description // 获取工单的评价信息
	 * @Date 3:32 PM 2019/7/8
	 * @Param [OrderId]
	 * @return java.util.Map<java.lang.String,java.lang.Object>
	 **/
	@Select("SELECT TOP 1 * FROM WorkOrderComm_T WHERE OrderId = #{OrderId} order by ID desc")
	Map<String,Object> getUserCommentInfoByOrderId(@Param("OrderId") Long OrderId);


	/**
	 * @Author Joe
	 * @Description   根据工单id获取工单号
	 * @Date 9:17 PM 2019/7/8
	 * @Param [OrderId]
	 * @return java.util.Map<java.lang.String,java.lang.Object>
	 **/
	@Select("SELECT * FROM WorkOrder_T WHERE ID = #{OrderId} AND Flag = 0")
	Map<String,Object> getOrderNoByOrderId(@Param("OrderId") Long OrderId);


	/**
	 * 保存DBU推荐三家服务站信息
	 * @Title: saveRecommendThreeStationToTable
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param map
	 * @param @return
	 * @return int
	 * @throws
	 */
	public int saveRecommendThreeStationToTable(Map<String,Object> map);

	/**
	 * @Author Joe
	 * @Description CAC审核通过更新工单状态
	 * @Date 2:27 PM 2019/7/24
	 * @Param [map]
	 * @return int
	 **/
	public int updateAllWorkOrderInfoByDBU(Map<String,Object> map);

	/**
	 * 通过渠道和ESN获取发动机信息
	 * @param map
	 * @return
	 */
	@Select("select * from EngineMsg where ESN = #{ESN}")
	public Map<String,Object> getEngineMsgByESNAndChannel(Map<String, Object> map);

	/**
	 * @Author Joe
	 * @Description 查询出所有没有OrderNoCrm的工单数据(根据工单号)
	 * @Date 3:41 PM 2019/5/7
	 * @Param [map]
	 * @return int
	 **/
	@Select("SELECT * FROM WorkOrder_T WHERE OrderNo = #{orderNo} AND Flag = 0")
	public Map<String,Object> selectWorkOrderInfoByOrderNo(@Param("orderNo") String orderNo);

	/**
	 * @Author Joe
	 * @Description 获取超时原因
	 * @Date 9:39 AM 2019/8/22
	 * @Param [map]
	 * @return java.util.Map<java.lang.String,java.lang.Object>
	 **/
	@Select("SELECT woot.* FROM WorkOrderOverTime_T woot\n" +
			"INNER JOIN WorkOrder_T wo ON wo.ID = woot.OrderId\n" +
			"WHERE wo.OrderNo = #{orderNo} AND woot.OrderStatus = #{OrderStatus} AND woot.Flag = 0")
	public Map<String,Object> getWorkOrderOverTimeInfo(Map<String, Object> map);

	/**
	 * @Author Joe
	 * @Description 获取失效模式代码
	 * @Date 10:53 AM 2019/8/28
	 * @Param [failureMode]
	 * @return java.util.Map<java.lang.String,java.lang.Object>
	 **/
	@Select("SELECT * FROM Dictionaries_T WHERE DTableName = 'InvalidModel' AND DInt = #{failureMode} AND Flag = 0")
	public Map<String,Object> getFailureModeCode(@Param("failureMode") int failureMode);

	/**
	 * @Author Joe
	 * @Description //根据企业ID获取岗位编号（XCEC为区域工程师WWID）
	 * @Date 1:53 PM 2019/9/3
	 * @Param [CompanyId]
	 * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
	 **/
	@Select("SELECT * FROM Position_T WHERE Creator = #{CompanyId} AND Flag = 0")
	public List<Map<String,Object>> getPositionByCompanyId(@Param("CompanyId") long CompanyId);

	/**
	 * @Author Joe
	 * @Description 根据企业ID去更新职位审核表Position_T（XCEC为区域工程师WWID）
	 * @Date 2:12 PM 2019/9/3
	 * @Param [CompanyId]
	 * @return int
	 **/
	@Update("UPDATE Position_T SET Flag = -1 WHERE Creator = #{CompanyId} AND Flag = 0 ")
	public int deletePositionByCompanyId(@Param("CompanyId") long CompanyId);


	/**
	 * @Author Joe
	 * @Description  更新异常数据的Comment
	 * @Date 4:00 PM 2019/9/10
	 * @Param [map]
	 * @return int
	 **/
	@Deprecated
	@Update("UPDATE WorkOrder_T SET Comment = #{Comment} WHERE OrderNo = #{OrderNo}")
	public int updateWorkOrderCommentByOrderNo(Map<String, Object> map);

	/**
	 * @Author Joe
	 * @Description 获取技师是否有此机型的授权
	 * @Date 10:59 AM 2019/9/5
	 * @Param [map]
	 * @return java.util.Map<java.lang.String,java.lang.Object>
	 **/
	@Select("SELECT * FROM EngineerQualify_T WHERE UserPhone = #{phone} AND EngineTypeName = #{engineType} AND Flag = 0")
	public Map<String,Object> getEngineerQualifyByPhoneAndTypeName(Map<String, Object> map);

	/**
	 * @Author Joe
	 * @Description 删除技师资质信息
	 * @Date 11:28 AM 2019/9/5
	 * @Param [map]
	 * @return java.util.Map<java.lang.String,java.lang.Object>
	 **/
	@Update("UPDATE EngineerQualify_T SET Flag = -1 WHERE UserPhone = #{UserPhone} AND EngineTypeName = #{EngineTypeName}")
	public Map<String,Object> deleteEngineerQualifyByPhoneAndTypeName(Map<String, Object> map);


	/**
	 * @Author Joe
	 * @Description 更新技师资质信息
	 * @Date 12:19 PM 2019/9/5
	 * @Param [map]
	 * @return int
	 **/
	public int updateEngineerQualifyByPhoneAndTypeName(Map<String, Object> map);



	/**
	 * @Author Joe
	 * @Description  查询技师资质信息
	 * @Date 10:49 AM 2019/10/9
	 * @Param [engineTypeName, userPhone]
	 * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
	 **/
	@Select("select * from EngineerQualify_T where UserPhone = #{userPhone} and EngineTypeName = #{engineTypeName}")
	public List<Map<String,Object>> getEngineerQualifyByPhoneAndEngineName(
			@Param("engineTypeName") String engineTypeName,@Param("userPhone") String userPhone);


	/**
	 * @Author Joe
	 * @Description // 更新服务技师资质信息
	 * @Date 11:16 AM 2019/10/9
	 * @Param [map]
	 * @return int
	 **/
	public int updateEngineerQualifyByPhoneAndEngineName(Map<String,Object> map);


	/**
	 * 根据服务商ID和企业ID获取服务商名称和授权信息
	 * @param map
	 * @return
	 */
	@Select("SELECT TOP 1 ssr.*,ss.StationName FROM SSRepair_T ssr\n" +
			"INNER JOIN ServiceStation_T ss ON ssr.ServiceStationID = ss.ID\n" +
			"WHERE ssr.ServiceStationID = #{ServiceStationId}  AND ssr.CompanyID = #{OrderChannel} AND ssr.Flag = 0")
	public Map<String,Object> getStationAndRepairInfoByStationIDAndCompanyID(Map<String,Object> map);

	/**
	 * 根据服务站编号和服务站与故障地点距离获取服务站维修范围表
	 */
	@Select("SELECT respair.BusinessNo AS stationNo,ss.PositionLat AS positionLat,ss.PositionLon AS positionLon FROM ServiceStation_T ss\n" +
			"INNER JOIN SSRepair_T respair ON ss.ID = respair.ServiceStationID\n" +
			"INNER JOIN Company_T company ON company.ID = respair.CompanyID\n" +
			"WHERE company.CompanyNo = #{serviceChannel} AND respair.Flag = 0 AND company.Flag = 0")
	public List<Map<String,Object>> getAllServiceStationByCompanyNo(Map<String, Object> map);


	/**
	 * 根据服务站编号和服务站与故障地点距离获取服务站维修范围表
	 */
	@Select("SELECT respair.BusinessNo AS stationNo,ss.PositionLat AS positionLon,ss.PositionLon AS positionLat FROM ServiceStation_T ss\n" +
			"INNER JOIN SSRepair_T respair ON ss.ID = respair.ServiceStationID\n" +
			"INNER JOIN Company_T company ON company.ID = respair.CompanyID\n" +
			"WHERE company.CompanyNo = #{serviceChannel} AND respair.Flag = 0 AND company.Flag = 0")
	public List<Map<String,Object>> getDCECAllServiceStationByCompanyNo(Map<String, Object> map);




	Map<String, Object> getDealerInfoByStationIdAndCompanyId(@Param("serviceStationId")Long serviceStationId, @Param("companyId")Long companyId);



	int insertDealerInfoSelective(Map<String, Object> dealerInfo);

	int updateDealerInfoSelectiveById(Map<String, Object> dealerInfo);










    public int deletePositionUserInfoToTable(Map<String, Object> map);

     int deletePositionUserList(List<Map<String, Object>> list);


    void deletePositionUserServiceStationInfo(Map<String, Object> appPositionMap);

    void deletePositionUserServiceStationByPositionUserList(List<Map<String, Object>> list);

    void deletePositionUserServiceStationByIdList(List<Map<String, Object>> list);


	/**
	 * 根据id删除PositionUser
	 * @param positionUserID
	 */
	@Update("UPDATE Position_T SET Flag = -1 WHERE ID = #{positionUserID}")
	void deletePositionUserById(Long positionUserID);

	/**
	 * 根据
	 */

	/**
	 * 根据id删除PositionUserServiceStation
	 * @param positionUserServiceStationID
	 */
	@Update("UPDATE PositionUserServiceStation_T SET Flag = -1 WHERE ID = #{positionUserServiceStationID}")
	void deletePositionUserServiceStationById(Long positionUserServiceStationID);

    /**
     * @description: DBU渠道 CRM同步服务站数据时，同步历史经销商数据给portal
      * @param: null
     * @return:
     * @exception:
     * @author: wunan
     * @company: Pactera Technology Co.,Ltd
     * @since: 2021/11/5 3:45
     * @version: V1.0
     */
	void insertHisDealerInfoForPortal(Map<String, Object> appPositionMap);
	void updateHisDealerInfoForPortal(Map<String, Object> appPositionMap);
	int checkHisDealerInfoExits(Map<String, Object> appPositionMap);

    int deletePositionContactToTableDcec(Map<String, Object> appPositionContactMap);
}
